home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / khtmlview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  19.7 KB  |  605 lines

  1. /* This file is part of the KDE project
  2.  
  3.    Copyright (C) 1997 Martin Jones (mjones@kde.org)
  4.              (C) 1998 Waldo Bastian (bastian@kde.org)
  5.              (C) 1998, 1999 Torben Weis (weis@kde.org)
  6.              (C) 1999 Lars Knoll (knoll@kde.org)
  7.              (C) 1999 Antti Koivisto (koivisto@kde.org)
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.  
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public License
  20.    along with this library; see the file COPYING.LIB.  If not, write to
  21.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22.    Boston, MA 02110-1301, USA.
  23. */
  24.  
  25. #ifndef KHTMLVIEW_H
  26. #define KHTMLVIEW_H
  27.  
  28. // qt includes and classes
  29. #include <qscrollview.h>
  30.  
  31. #include <kdelibs_export.h>
  32.  
  33. class QPainter;
  34. class QRect;
  35. template< typename T > class QValueVector;
  36.  
  37. namespace DOM {
  38.     class HTMLDocumentImpl;
  39.     class DocumentImpl;
  40.     class ElementImpl;
  41.     class HTMLElementImpl;
  42.     class HTMLTitleElementImpl;
  43.     class HTMLGenericFormElementImpl;
  44.     class HTMLFormElementImpl;
  45.     class HTMLAnchorElementImpl;
  46.     class HTMLInputElementImpl;
  47.     class Range;
  48.     class NodeImpl;
  49.     class CSSProperty;
  50. }
  51.  
  52. namespace KJS {
  53.     class WindowFunc;
  54.     class ExternalFunc;
  55. }
  56.  
  57. namespace khtml {
  58.     class RenderObject;
  59.     class RenderCanvas;
  60.     class RenderStyle;
  61.     class RenderLineEdit;
  62.     class RenderPartObject;
  63.     class RenderWidget;
  64.     class CSSStyleSelector;
  65.     class LineEditWidget;
  66.     class CaretBox;
  67.     void applyRule(DOM::CSSProperty *prop);
  68. }
  69.  
  70. class KHTMLPart;
  71. class KHTMLViewPrivate;
  72.  
  73. /**
  74.  * Renders and displays HTML in a QScrollView.
  75.  *
  76.  * Suitable for use as an application's main view.
  77.  **/
  78. class KHTML_EXPORT KHTMLView : public QScrollView
  79. {
  80.     Q_OBJECT
  81.  
  82.     friend class DOM::HTMLDocumentImpl;
  83.     friend class DOM::HTMLTitleElementImpl;
  84.     friend class DOM::HTMLGenericFormElementImpl;
  85.     friend class DOM::HTMLFormElementImpl;
  86.     friend class DOM::HTMLAnchorElementImpl;
  87.     friend class DOM::HTMLInputElementImpl;
  88.     friend class DOM::DocumentImpl;
  89.     friend class KHTMLPart;
  90.     friend class khtml::RenderCanvas;
  91.     friend class khtml::RenderObject;
  92.     friend class khtml::RenderLineEdit;
  93.     friend class khtml::RenderPartObject;
  94.     friend class khtml::RenderWidget;
  95.     friend class khtml::CSSStyleSelector;
  96.     friend class khtml::LineEditWidget;
  97.     friend class KJS::WindowFunc;
  98.     friend class KJS::ExternalFunc;
  99.     friend void khtml::applyRule(DOM::CSSProperty *prop);
  100.  
  101.  
  102. public:
  103.     /**
  104.      * Constructs a KHTMLView.
  105.      */
  106.     KHTMLView( KHTMLPart *part, QWidget *parent, const char *name=0 );
  107.     virtual ~KHTMLView();
  108.  
  109.     /**
  110.      * Returns a pointer to the KHTMLPart that is
  111.      * rendering the page.
  112.      **/
  113.     KHTMLPart *part() const { return m_part; }
  114.  
  115.     int frameWidth() const { return _width; }
  116.  
  117.     /**
  118.      * Sets a margin in x direction.
  119.      */
  120.     void setMarginWidth(int x);
  121.  
  122.     /**
  123.      * Returns the margin width.
  124.      *
  125.      * A return value of -1 means the default value will be used.
  126.      */
  127.     int marginWidth() const { return _marginWidth; }
  128.  
  129.     /*
  130.      * Sets a margin in y direction.
  131.      */
  132.     void setMarginHeight(int y);
  133.  
  134.     /**
  135.      * Returns the margin height.
  136.      *
  137.      * A return value of -1 means the default value will be used.
  138.      */
  139.     int marginHeight() { return _marginHeight; }
  140.  
  141.     /**
  142.      * Sets verticals scrollbar mode. Reimplemented for internal reasons.
  143.      */
  144.     virtual void setVScrollBarMode ( ScrollBarMode mode );
  145.  
  146.     /**
  147.      * Sets horizontal scrollbar mode. Reimplemented for internal reasons.
  148.      */
  149.     virtual void setHScrollBarMode ( ScrollBarMode mode );
  150.  
  151.     /**
  152.      * Prints the HTML document.
  153.      */
  154.     void print();
  155.  
  156.     /**
  157.      * Prints the HTML document.
  158.      * @param quick if true, fully automated printing, without print dialog
  159.      */
  160.     void print( bool quick ); // KDE 4.0: merge with above
  161.  
  162.     /**
  163.      * ensure the display is up to date
  164.      */
  165.     void layout(); // KDE 4.0: make private
  166.     /**
  167.      * Display all accesskeys in small tooltips
  168.      */
  169.     void displayAccessKeys();
  170.  
  171.  
  172.  
  173. signals:
  174.     /**
  175.      * This signal is used for internal layouting. Don't use it to check if rendering finished.
  176.      * Use @ref KHTMLPart completed() signal instead.
  177.      */
  178.     void finishedLayout();
  179.     void cleared();
  180.     void zoomView( int );
  181.     void hideAccessKeys();
  182.     void repaintAccessKeys();
  183.     void findAheadActive( bool );
  184.  
  185. protected:
  186.     void clear();
  187.  
  188.     virtual void resizeEvent ( QResizeEvent * event );
  189.     virtual void showEvent ( QShowEvent * );
  190.     virtual void hideEvent ( QHideEvent *);
  191.     virtual bool focusNextPrevChild( bool next );
  192.     virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
  193.     virtual void drawContents( QPainter* );
  194.     virtual void viewportMousePressEvent( QMouseEvent * );
  195.     virtual void focusInEvent( QFocusEvent * );
  196.     virtual void focusOutEvent( QFocusEvent * );
  197.     virtual void viewportMouseDoubleClickEvent( QMouseEvent * );
  198.     virtual void viewportMouseMoveEvent(QMouseEvent *);
  199.     virtual void viewportMouseReleaseEvent(QMouseEvent *);
  200.     virtual void viewportResizeEvent(QResizeEvent*);
  201. #ifndef QT_NO_WHEELEVENT
  202.     virtual void viewportWheelEvent(QWheelEvent*);
  203. #endif
  204.     virtual void dragEnterEvent( QDragEnterEvent* );
  205.     virtual void dropEvent( QDropEvent* );
  206.     virtual void closeEvent ( QCloseEvent * );
  207.     virtual bool eventFilter(QObject *, QEvent *);
  208.  
  209.     void keyPressEvent( QKeyEvent *_ke );
  210.     void keyReleaseEvent ( QKeyEvent *_ke );
  211.     void contentsContextMenuEvent ( QContextMenuEvent *_ce );
  212.     void doAutoScroll();
  213.     void timerEvent ( QTimerEvent * );
  214. protected slots:
  215.     void slotPaletteChanged();
  216.     void slotScrollBarMoved();
  217.  
  218. private slots:
  219.     void tripleClickTimeout();
  220.     void findTimeout();
  221.     void accessKeysTimeout();
  222.  
  223.     /**
  224.     * @internal
  225.     * @since 3.4
  226.     * used for autoscrolling with MMB
  227.     */
  228.     void slotMouseScrollTimer();
  229.  
  230. private:
  231.  
  232.     void scheduleRelayout(khtml::RenderObject* clippedObj=0);
  233.     void unscheduleRelayout();
  234.  
  235.     void scheduleRepaint(int x, int y, int w, int h, bool asap=false);
  236.     void unscheduleRepaint();
  237.  
  238.     bool needsFullRepaint() const;
  239.  
  240.     void closeChildDialogs();
  241.     bool dialogsAllowed();
  242.  
  243.     /**
  244.      * Paints the HTML document to a QPainter.
  245.      * The document will be scaled to match the width of
  246.      * rc and clipped to fit in the height.
  247.      * yOff determines the vertical offset in the document to start with.
  248.      * more, if nonzero will be set to true if the documents extends
  249.      * beyond the rc or false if everything below yOff was painted.
  250.      **/
  251.     void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = 0);
  252.  
  253. #if 0
  254.     /**
  255.      * Paints the HTML document to a QPainter.
  256.      * The document will be scaled to match the width.
  257.      **/
  258.     void paint(QPainter *p, int width);
  259. #endif
  260.  
  261.     /**
  262.      * Get/set the CSS Media Type.
  263.      *
  264.      * Media type is set to "screen" for on-screen rendering and "print"
  265.      * during printing. Other media types lack the proper support in the
  266.      * renderer and are not activated. The DOM tree and the parser itself,
  267.      * however, properly handle other media types. To make them actually work
  268.      * you only need to enable the media type in the view and if necessary
  269.      * add the media type dependent changes to the renderer.
  270.      */
  271.     void setMediaType( const QString &medium );
  272.     QString mediaType() const;
  273.  
  274.     bool pagedMode() const;
  275.  
  276.     bool scrollTo(const QRect &);
  277.  
  278.     bool focusNextPrevNode(bool next);
  279.     bool handleAccessKey(const QKeyEvent* ev);
  280.     bool focusNodeWithAccessKey(QChar c, KHTMLView* caller = NULL);
  281.     QMap< DOM::ElementImpl*, QChar > buildFallbackAccessKeys() const;
  282.     void displayAccessKeys( KHTMLView* caller, KHTMLView* origview, QValueVector< QChar >& taken, bool use_fallbacks );
  283.  
  284.     void useSlowRepaints();
  285.  
  286.     void setIgnoreWheelEvents(bool e);
  287.  
  288.     void init();
  289.  
  290.     DOM::NodeImpl *nodeUnderMouse() const;
  291.     DOM::NodeImpl *nonSharedNodeUnderMouse() const;
  292.  
  293.     void restoreScrollBar();
  294.  
  295.     QStringList formCompletionItems(const QString &name) const;
  296.     void clearCompletionHistory(const QString& name);
  297.     void addFormCompletionItem(const QString &name, const QString &value);
  298.  
  299.     void addNonPasswordStorableSite( const QString& host );
  300.     bool nonPasswordStorableSite( const QString& host ) const;
  301.  
  302.     bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode,
  303.                 DOM::NodeImpl *targetNodeNonShared, bool cancelable,
  304.                 int detail,QMouseEvent *_mouse, bool setUnder,
  305.                 int mouseEventType);
  306.     bool dispatchKeyEvent( QKeyEvent *_ke );
  307.     bool dispatchKeyEventHelper( QKeyEvent *_ke, bool generate_keypress );
  308.  
  309.     void complete( bool pendingAction );
  310.  
  311. #ifndef KHTML_NO_TYPE_AHEAD_FIND
  312.     void findAhead(bool increase);
  313.     void updateFindAheadTimeout();
  314.     void startFindAhead( bool linksOnly );
  315. #endif // KHTML_NO_TYPE_AHEAD_FIND
  316.  
  317. #ifndef KHTML_NO_CARET
  318.     // -- caret-related member functions (for caretMode as well as designMode)
  319.  
  320.     /** initializes the caret if it hasn't been initialized yet.
  321.      *
  322.      * This method determines a suitable starting position, initializes
  323.      * the internal structures, and calculates the caret's coordinates ready
  324.      * for display.
  325.      *
  326.      * To "deinitialize" the caret, call caretOff
  327.      * @param keepSelection @p true to keep any active selection. It may have
  328.      *         been extended if the caret position is changed.
  329.      */
  330.     void initCaret(bool keepSelection = false);
  331.     /** returns whether the text under the caret will be overridden.
  332.       */
  333.     bool caretOverrides() const;
  334.     /** ensures that the given element is properly focused.
  335.      *
  336.      * If not in caret mode or design mode, keyboard events are only regarded for
  337.      * focused nodes. Therefore, the function ensured that the focus will be
  338.      * properly set on unfocused nodes (or on a suitable ancestor).
  339.      * @param node node to focus
  340.      */
  341.     void ensureNodeHasFocus(DOM::NodeImpl *node);
  342.     /** inquires the current caret position and stores it in the caret view
  343.      * context. Also resets the blink frequency timer. It will not display
  344.      * the caret on the canvas.
  345.      * @param hintBox caret box whose coordinates will be used if the
  346.      * caret position could not be determined otherwise.
  347.      */
  348.     void recalcAndStoreCaretPos(khtml::CaretBox *hintBox = 0);
  349.     /** displays the caret and reinitializes the blink frequency timer.
  350.      *
  351.      * The caret will only be displayed on screen if the view has focus, or
  352.      * the caret display policy allows it. The same holds true for the blink
  353.      * frequency timer.
  354.      */
  355.     void caretOn();
  356.     /** hides the caret and kills the blink frequency timer.
  357.      *
  358.      * These operations are executed unconditionally, regardless of the
  359.      * focus, and the caret display policy.
  360.      */
  361.     void caretOff();
  362.     /** makes the caret visible, but does not influence the frequency timer.
  363.      * That means it probably won't get visible immediately.
  364.      *
  365.      * These operations are executed unconditionally, regardless of the
  366.      * focus, and the caret display policy.
  367.      * @param forceRepaint @p true to force an immediate repaint, otherwise
  368.      *        do a scheduled repaint
  369.      */
  370.     void showCaret(bool forceRepaint = false);
  371.     /** makes the caret invisible, but does not influence the frequency timer.
  372.      * The caret is immediately hidden.
  373.      *
  374.      * These operations are executed unconditionally, regardless of the
  375.      * focus, and the caret display policy.
  376.      */
  377.     void hideCaret();
  378.     /** shifts the viewport to ensure that the caret is visible.
  379.      *
  380.      * Note: this will also work if the caret is hidden.
  381.      */
  382.     void ensureCaretVisible();
  383.  
  384.     /** folds the selection to the current caret position.
  385.      *
  386.      * Whatever selection has existed before will be removed by the invocation
  387.      * of this method. Updates are only done if an actual selection has
  388.      * been folded. After the call of this method, no selection will exist
  389.      * any more.
  390.      *
  391.      * No validity checking is done on the parameters. Note that the parameters
  392.      * refer to the old selection, the current caret may be way off.
  393.      * @param startNode starting node of selection
  394.      * @param startOffset offset within the start node.
  395.      * @param endNode ending node of selection
  396.      * @param endOffset offset within the end node.
  397.      * @return @p true if there had been a selection, and it was folded.
  398.      */
  399.     bool foldSelectionToCaret(DOM::NodeImpl *startNode, long startOffset,
  400.                     DOM::NodeImpl *endNode, long endOffset);
  401.  
  402.     /** places the caret on the current position.
  403.      *
  404.      * The caret is switched off, the position recalculated with respect to
  405.      * the new position. The caret will only be redisplayed if it is on an
  406.      * editable node, in design mode, or in caret mode.
  407.      * @param hintBox caret box whose coordinates will be used if the
  408.      * caret position could not be determined otherwise.
  409.      * @return @p true if the caret has been displayed.
  410.      */
  411.     bool placeCaret(khtml::CaretBox *hintBox = 0);
  412.  
  413.     /** extends the selection up to the current caret position.
  414.      *
  415.      * When a selection exists, the function adds/removes pieces from the
  416.      * beginning/end of the selection up to the current caret position.
  417.      *
  418.      * The selection values are *not* normalized, i. e. the resulting end
  419.      * position may actually precede the starting position.
  420.      *
  421.      * No validity checking is done on the parameters. Note that the parameters
  422.      * refer to the old selection, the current caret may be way off.
  423.      * @param startNode starting node of selection
  424.      * @param startOffset offset within the start node.
  425.      * @param endNode ending node of selection
  426.      * @param endOffset offset within the end node.
  427.      * @return @p true when the current selection has been changed
  428.      */
  429.     bool extendSelection(DOM::NodeImpl *startNode, long startOffset,
  430.                 DOM::NodeImpl *endNode, long endOffset);
  431.  
  432.     /** updates the selection from the last to the current caret position.
  433.      *
  434.      * No validity checking is done on the parameters. Note that the parameters
  435.      * refer to the old selection, the current caret may be way off.
  436.      * @param startNode starting node of selection
  437.      * @param startOffset offset within the start node.
  438.      * @param endNode ending node of selection
  439.      * @param endOffset offset within the end node.
  440.      */
  441.     void updateSelection(DOM::NodeImpl *startNode, long startOffset,
  442.             DOM::NodeImpl *endNode, long endOffset);
  443.  
  444.     /**
  445.      * Returns the current caret policy when the view is not focused.
  446.      * @return a KHTMLPart::CaretDisplay value
  447.      */
  448.     int caretDisplayPolicyNonFocused() const;
  449.  
  450.     /**
  451.      * Sets the caret display policy when the view is not focused.
  452.      * @param policy new display policy as
  453.      *        defined by KHTMLPart::CaretDisplayPolicy
  454.      * @since 3.2
  455.      */
  456.     void setCaretDisplayPolicyNonFocused(int policy);
  457.  
  458.     // -- caret event handler
  459.  
  460.     /**
  461.      * Evaluates key presses on editable nodes.
  462.      */
  463.     void caretKeyPressEvent(QKeyEvent *);
  464.  
  465.     // -- caret navigation member functions
  466.  
  467.     /** moves the caret to the given position and displays it.
  468.      *
  469.      * If the node resembles an invalid position, the function sets the caret to a
  470.      * nearby node that is valid.
  471.      *
  472.      * @param node node to be set to
  473.      * @param offset zero-based offset within this node
  474.      * @param clearSelection @p true if any selection should be cleared
  475.      *    as well.
  476.      * @return @p true if a previously existing selection has been changed.
  477.      */
  478.     bool moveCaretTo(DOM::NodeImpl *node, long offset, bool clearSelection);
  479.  
  480.     /**
  481.      * Movement enumeration
  482.      * @li CaretByCharacter move caret character-wise
  483.      * @li CaretByWord move caret word-wise
  484.      */
  485.     enum CaretMovement { CaretByCharacter, CaretByWord };
  486.  
  487.     /** moves the caret.
  488.      *
  489.      * @param next @p true, move towards the following content, @p false,
  490.      *        move towards the previous
  491.      * @param cmv CaretMovement operation
  492.      * @param n count the CaretMovement has to be carried out.
  493.      * For latin documents, a positive number means moving the caret
  494.      * these many characters to the right/downwards, a negative number
  495.      * to the left/upwards. For RTL documents, the opposite applies.
  496.      */
  497.     void moveCaretBy(bool next, CaretMovement cmv, int n);
  498.  
  499.     /** moves the caret by line.
  500.      */
  501.     void moveCaretByLine(bool next, int n);
  502.  
  503.     /** moves the caret to the given line boundary.
  504.      * @param end @p true if the caret is to be moved to the end of the line,
  505.      *        otherwise to the beginning.
  506.      */
  507.     void moveCaretToLineBoundary(bool end);
  508.  
  509.     /** moves the caret to the given document boundary.
  510.      * @param end @p true if the caret is to be moved to the end of the
  511.      *        document, otherwise to the beginning.
  512.      */
  513.     void moveCaretToDocumentBoundary(bool end);
  514.  
  515.     /** does the actual caret placement so that it becomes visible at
  516.      * the new position.
  517.      *
  518.      * This method is only suitable if the new caret position has already been
  519.      * determined.
  520.      * @param hintBox caret box whose coordinates will be used if the
  521.      * caret position could not be determined otherwise.
  522.      */
  523.     void placeCaretOnChar(khtml::CaretBox *hintBox);
  524.  
  525.     /** does the actual caret placement so that it becomes visible at
  526.      * the new position.
  527.      *
  528.      * Additionally, it calculates the new caret position from the given
  529.      * box and coordinates.
  530.      *
  531.      * @param caretBox caret box serving as a measurement point for offset.
  532.      * @param x x-coordinate relative to containing block. The offset will
  533.      *        be approximated as closely as possible to this coordinate,
  534.      *        but never less than caretBox->xPos() and greater than
  535.      *        caretBox->xPos() + caretBox->width()
  536.      * @param absx absolute x-coordinate of containing block, needed for
  537.      *        calculation of final caret position
  538.      * @param absy absolute y-coordinate of containing block, needed for
  539.      *        calculation of final caret position
  540.      */
  541.     void placeCaretOnLine(khtml::CaretBox *caretBox, int x, int absx, int absy);
  542.  
  543.     /** moves the caret by a page length.
  544.      * @param next @p true, move down, @p false, move up.
  545.      */
  546.     void moveCaretByPage(bool next);
  547.  
  548.     /** moves the caret to the beginning of the previous word.
  549.      */
  550.     void moveCaretPrevWord();
  551.  
  552.     /** moves the caret to the beginning of the next word.
  553.      */
  554.     void moveCaretNextWord();
  555.  
  556.     /** moves the caret to the previous line.
  557.      *
  558.      * @param n number of lines to move caret
  559.      */
  560.     void moveCaretPrevLine(int n = 1);
  561.  
  562.     /** moves the caret to the following line.
  563.      *
  564.      * @param n number of lines to move caret
  565.      */
  566.     void moveCaretNextLine(int n = 1);
  567.  
  568.     /** moves the caret to the previous page
  569.      */
  570.     void moveCaretPrevPage();
  571.  
  572.     /** moves the caret to the next page
  573.      */
  574.     void moveCaretNextPage();
  575.  
  576.     /** moves the caret to the beginning of the current line.
  577.      */
  578.     void moveCaretToLineBegin();
  579.  
  580.     /** moves the caret to the end of the current line.
  581.      */
  582.     void moveCaretToLineEnd();
  583.  
  584. #endif // KHTML_NO_CARET
  585.  
  586.     // ------------------------------------- member variables ------------------------------------
  587.  private:
  588.  
  589.     void setWidgetVisible(::khtml::RenderWidget*, bool visible);
  590.  
  591.     int _width;
  592.     int _height;
  593.  
  594.     int _marginWidth;
  595.     int _marginHeight;
  596.  
  597.     KHTMLPart *m_part;
  598.     KHTMLViewPrivate *d;
  599.  
  600.     QString m_medium;   // media type
  601. };
  602.  
  603. #endif
  604.  
  605.